#! /usr/bin/env python
# -*- coding: utf-8 -*-
import time

from playwright.sync_api import Page

from common.base_page import BasePage
from common.logger import logger
from locators.majorHazardSourceSafety.majorRiskCtrl.majorHazardSourceRiskEvaluationWarn.loc_query import LocQuery
from locators.majorHazardSourceSafety.majorRiskCtrl.majorHazardSourceRiskEvaluationWarn.loc_view import LocView


class EvaluationWarn(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('重大危险源安全管理')
        self.switch_menu('重大风险管控')
        self.switch_menu('重大危险源风险评估')
        self.switch_menu('重大危险源风险评估预警')

    def query_total_list(self, loc_tab, company_name, danger_name, evaluation_level, start_date, end_date):
        """
        测试查询
        :param loc_tab: 评价结果和历史结果的loc
        :param company_name:
        :param danger_name:
        :param evaluation_level:
        :param start_date:
        :param end_date:
        :return:
        """
        logger.info('开始重大危险源风险评估预警查询测试')
        logger.info('点击标签页')
        self.click(loc_tab)
        # 强制等待3s，保证切换tab页之后，页面数据加载完成
        time.sleep(3)
        logger.info('选择企业名称')
        self.select(LocQuery.loc_company, company_name)
        logger.info('输入重大危险源名称')
        self.fill(LocQuery.loc_danger_name, danger_name)
        logger.info('选择动态评级')
        self.select(LocQuery.loc_evaluation_level, evaluation_level)
        logger.info('输入平均日期')
        self.fill_date_time(LocQuery.loc_evaluation_date, start_date, end_date)
        self.click(LocQuery.loc_query, exact=True)

    def reset(self, ):
        """
        测试重置
        :return:
        """
        logger.info('开始重大危险源风险评估预警查询重置测试')
        logger.info('点击重置按钮')
        self.click(LocQuery.loc_reset, exact=True)

    def view(self, loc_tab):
        """
        测试查看
        :param loc_tab:
        :return:
        """
        logger.info('开始重大危险源风险评估预警记录查看测试')
        logger.info('点击标签页')
        self.click(loc_tab)
        # 强制等待3s，保证切换tab页之后，页面数据加载完成
        time.sleep(3)
        logger.info('点击查看按钮')
        self.click(LocView.loc_button_view)
